home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_327 / softfont / convert.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  140 lines

  1. /*************************************************************** 
  2.  *  convert.c     portrait font to landscape  HP LaserJet II format 
  3.  *    Compiled under Lattice C Compiler vers 5.04 
  4.  *
  5.  * Call: convert(portrait,landscape)
  6.  *
  7.  *  by Tom Lynch, 
  8.  *  25 January 1989
  9.  ***************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <exec/types.h>
  13. #include <libraries/dos.h>
  14.  
  15. extern long DOSBase;
  16.  
  17. FILE *fp,*fl;
  18.  
  19. int filepos = 0; /* position in file being read  (32 bits in AMIGA */
  20. int filend = 0; /* file end flag  */
  21. int n = 0;    /* value counter */
  22.  
  23. char c;        /* character read from portrait font file */
  24. char rdchar();     /* define function to return char */
  25. char skip();     /* define function to return char */
  26. char change();     /* define function to return char */
  27.  
  28.  
  29. char convert(char *p, char *l)    /* CLI format: PORTOLAN font.port(old) font.land(new) */
  30.          {
  31.  
  32.     extern char c;        /* reference externals */
  33.     extern FILE *fp, *fl; 
  34.     extern int n;
  35.     extern char rdchar();
  36.     extern char skip();
  37.     extern char change();
  38.     extern int measureto();
  39.  
  40.     DOSBase = OpenLibrary("dos.library",0);
  41.        
  42.     if ((fp = fopen(p,"r")) == NULL)    {
  43.              return(4); 
  44.          }
  45.            if ((fl = fopen(l,"w")) == NULL)    {
  46.              return(5); 
  47.          }
  48.          
  49.     /* files ready, convert portrait file to landscape */
  50.  
  51.     rdchar();      /* look for initial escape character */
  52.     if (c != (char)'\033') return(6);
  53.            skip(2);      /* esc, ')', and 's' of font descriptor */
  54.            measureto ('W');  /* read index 'n' that points to next esc */
  55.            skip(12);      /* skip to orientation byte */
  56.     change(0,1);      /* change from port(0) to land(1) */
  57.     skip(n-13);      /* skip to end of font descriptor */
  58.     rdchar();      /* read first byte of charater descriptor */
  59.     while (filend == 0) {    /* test for end of charaters in font */
  60.         skip (2);    /* '*' and 'c' of char descriptor */
  61.         measureto('E');    /* read charater number */
  62.         skip(3);    /* bypass esc, '(', 's' */
  63.         measureto('W');    /* read char descriptor length */
  64.         skip(1);    /* skip length byte */
  65.         rdchar();    /* read continuation byte */
  66.         if (c == 0) {    /*   field =0 for new char */
  67.             skip(2);      /* skip descriptor size, class */
  68.             change(0,1);     /* change charater orientation */
  69.         }
  70.         else    {    /* data from prev char if data ln>32768 bytes */
  71.             skip(3);    /* therefore skip over orientation byte */
  72.         }
  73.                  skip (n-5);
  74.                  rdchar ();    /* read, expecting escape for next char */
  75.     }
  76.         c = fcloseall();    /* if filend = 0, success */
  77.         return NULL;
  78. }
  79.  
  80. char rdchar () {    /* read byte store in char 'c' */
  81.     extern char c;
  82.     extern FILE *fp, *fl; 
  83.     int r;
  84.     filepos++;
  85.     c = fgetc(fp);
  86.     if ((filend = feof(fp)) != 0)     return 0; 
  87.     r = fputc(c,fl);
  88.      return   c;
  89. }
  90.  
  91. char skip(int n)      {        /* skip 'n' bytes in file */
  92.     extern char c;
  93.     extern FILE *fp, *fl; 
  94.     int x, r;
  95.     for (x = 0; x < n; ++x)
  96.         { 
  97.         filepos++;
  98.         c = fgetc(fp);
  99.         if ((filend = feof(fp)) != 0) return 0; 
  100.         r = fputc(c,fl);
  101.     }
  102.     return c;
  103.        
  104. char change(int prev, int new) /* change byte  */
  105.        {
  106.     extern char c;
  107.     extern FILE *fp, *fl; 
  108.     int r;
  109.     filepos++;
  110.     c = fgetc(fp);
  111.     if (c == prev) r = fputc(new,fl);
  112.     else  r = fputc(new,fl);
  113.     return c;
  114.  
  115.  
  116.  
  117. measureto (char test)    /* calculate ascii format number (base 10) */
  118.        {
  119.     char rdchar();
  120.     extern char c;
  121.     rdchar();
  122.     n = (c - '0');        /* convert from ASCII to integer */
  123.     rdchar();            /* good for 1 to 5 character number */
  124.     if (c == test) return n;
  125.     n = n*10 + (c - '0');
  126.     rdchar();
  127.     if (c == test) return n;
  128.     n = n*10 + (c - '0');
  129.     rdchar();
  130.     if (c == test) return n;
  131.     n = n*10 + (c - '0');
  132.     rdchar();
  133.     if (c == test) return n;
  134.     n = n*10 + (c - '0');
  135.     rdchar();            /* this will read 'test' character */
  136.     return n;            /* with 5 character ascii number   */
  137. }
  138.